package com.hyacinth.future;

/**
 * @author zhangfb
 * @version 1.0.0.1
 * @since JDK 1.8
 */
public class Client {

    public Data request(final String queryStr) {
        final FutureDate future = new FutureDate();
        new Thread(new Runnable() {
            @Override
            public void run() {
                RealData realData = new RealData(queryStr);
                future.setResult(realData);
            }
        }).start();
        return future;
    }

    public static void main(String[] args) {
        Client client = new Client();
        System.out.println("发起请求。。。");
        Data data = client.request("name");
        System.out.println("请求完毕。。。");
        try {
            System.out.println("执行业务逻辑开始。。。");
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("执行业务逻辑结束");
        System.out.println("获取请求结果，res="+data.getResult());
    }
}
